package cn.edu.ujn.ch14.c;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.ujn.ch14.m.User;

@Controller
public class UserController {
	@RequestMapping("/find")
	@ResponseBody
	public User findUser(User user) {
		System.out.println(user);
		return user;
	}
	@RequestMapping("/index")
	public String toIndex() {
		return "index";
	}
	@RequestMapping("/testJson")
	@ResponseBody
	public User testJson(@RequestBody User user) {
		System.out.println(user);
		user.setUsername(user.getUsername()+",hello!");
		return user;
	}
	
	@RequestMapping("/rest")
	public String toRest() {
		return "restful";
	}
	@RequestMapping(method = RequestMethod.GET,value = "/user/{id}")
	@ResponseBody
	public User selectUser(@PathVariable("id") String id) {
		System.out.println(id);
		User user = new User();
		if("1".equals(id)) {
			user.setUsername("liukun");
			user.setPassword("787777");
		}
		return user;
	}

}










